/**
 * 基本数据类型
*/
let num: number = 123
let str: string = '123'
let bool: boolean = true
/**
 * 联合类型
*/
let num1: (number | string) = '123'
let num2: (number | null) = null
let num3: (number | undefined) = 123
/**
 * 数组
*/
let arr1: (number | string)[] = [1, 5, 6]
let arr2: string[] = ['a']
let arr3: Array<string | number> = [1, '22']

/**
 * type别名
*/
type Array1 = (number | string)[]
type Str = String
let arr4: Array1 = [1, '1213']
let str4: Str = '555'

const add = (a: number, b: number): void => {
    console.log(a + b)
}
const add1 = (a: number, b: number): number => {
    return a + b
}
const add2 = (a: number, b: number): undefined => {
    return undefined
}

const add3 = (a: number, b?: number): number => {
    return b ? a + b : a
}


let obj:{
    name:string,
    age:number | undefined,
    sex?:string
} = {
    name:'',
    age:undefined
}

interface Person{
    name:string,
    age:number | undefined,
    sex?:string
}
let obj1:Person={
    name:'',
    age:undefined,
}

function strType<T>(value:T){return value}
let strTest = strType<string|number>('a')
let objTest1 = strType<Person>({
    name:'',
    age:18
})
let arrTest:Array<Person> = [
    {
        name:'',
        age:18
    }
]

let objTest:{
    arr:Array<Person>
} = {
    arr:[{
        name:'age',
        age:18
    }]
}

let lqq:any = 'abc'
lqq=123
lqq=true

let arrLqq:[number,string] = [1,'2']
arrLqq.push('q')
// arrLqq.push(true)


let WObj:{
    readonly name:string
} = {
    name:''
}

let str1 = 'abc'
// str1 =true (错误，推断为字符型)
let str2:1 | 'abc' | 0 
// str1 =true (错误，只能是1、'abc'、0其中一个)


function addTest():number | string{
    return '1'
}


let enumArr:[string,number] = ['123',1]


enum types {
    a = -1,b,c
}
console.log(types['b'] === 0)